<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    await is only valid in async functions and the top level bodies of modules
    await只能在async函数或者顶级的modules体

    
    <script type="module">
        // 这样可以
        const data=  await new Promise((resolve,reject)=>{
            resolve('data')
        })
        console.log(data)

        
       
    </script>

    <script>

       
        try {

             // 错误的
            const ha=  await new Promise((resolve,reject)=>{
            resolve('ha')
            })
            console.log(ha)
        } catch (error) {
            console.log(error)
        }
       

        // 正确的
        async function halo(){
                // 这样会报错
            const ha=  await new Promise((resolve,reject)=>{
                resolve('ha')
            })
            console.log(ha)
        }

        console.log(halo)
        halo();

    </script>

 

</body>
</html>